
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>创建日程</title>
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <!-- import Vue before Element -->
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <!-- import JavaScript -->
  <script src="js/axios.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <link rel="stylesheet" href="layui/css/layui.css">
  <script src="layui/layui.js"></script>
  <style type="text/css">
  	#app{
  		margin: auto;
  	}
  	#app form{
  			margin: 15px;
  	}
  </style>

</head>
<body>
  <div id="app">
  	<div class="jiange">

  	</div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="标题" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="设定时间" >
        <el-col :span="11">
          <el-date-picker type="datetime" placeholder="开始时间" v-model="startTime" style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="1">-</el-col>
        <el-col :span="11">
          <el-date-picker type="datetime" placeholder="结束时间" v-model="endTime" style="width: 100%;"></el-date-picker>
        </el-col>
        </el-time-select>
      </el-form-item>
      <el-form-item label="提醒时间" >
        <el-date-picker
          v-model="firstRemind"
          type="datetime"
          placeholder="请选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="二次提醒" >
        <el-date-picker
          v-model="secondRemind"
          type="datetime"
          placeholder="请选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理人" >
        张三
      </el-form-item>

      <el-form-item label="备注" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>
      <el-form-item >
        <el-button type="primary" @click="resetForm('ruleForm')" style="float:right; margin-right:20px;">取消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" style="float:right; margin-right:20px;">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</body>

  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          ruleForm: {
            name: '',
            region: '',
            date1: '',
            date2: '',
            delivery: false,
            type: [],
            resource: '',
            desc: ''
          },
          rules: {
            name: [
              { required: true, message: '请输入标题', trigger: 'blur' },
              { min: 2, message: '长度在2汉字以上', trigger: 'blur' }
            ],
            region: [
              { required: true, message: '请选择设定时间', trigger: 'blur' }
            ],
            date1: [
              { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
            ],
            date2: [
              { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
            ],
            type: [
              { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
            ],
            resource: [
              { required: true, message: '请选择活动资源', trigger: 'change' }
            ],
            desc: [
              { required: true, message: '请输入备注', trigger: 'blur' }
            ]
          },
          firstRemind: "",
          secondRemind: "",
          startTime: "",
          endTime: "",
          createDate: '',
          tripDate:''
        };
      },
      methods: {
        submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              console.log(this.endTime);
              console.log(this.tripDate);
              axios.post(developURL+richengDK+'/trip/add', {
                  "title": this.ruleForm.name,
                  "tripDate": this.tripDate, //this.tripDate, 2018-08-25 //"2018-08-20T06:17:45.000+0000",
                  "startTime": this.startTime || "2018-08-20T06:17:45.000+0000",
                  "endTime": this.endTime || "2018-08-20T06:17:45.000+0000",
                  "oneCallTime": this.firstRemind || "2018-08-20T06:17:45.000+0000",
                  "twoCallTime": this.secondRemind || "2018-08-20T06:17:45.000+0000",
                  "content": this.ruleForm.desc,
                  "tripUserid": '1110',
                  "createDate": "2018-08-20T06:17:45.000+0000"//this.createDate || "2018-08-20T06:17:45.000+0000"
              }).then(function (response) {
              // 　　alert();
                  console.log(response)
              }).catch(function (error) {
              　　alert(error);
              });
              alert('创建成功!');
              //提示层
            	// var layer = layui.layer
              // layer.msg('日程创建成功');
              setTimeout(function(){
                parent.layer.closeAll();
              },1000)
              // setTimeout(()=>{this.window.close},1000);
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        resetForm(formName) {
          this.$refs[formName].resetFields();
        }
      },
      mounted: function(){
        //时间格式
        var jinYueDate = window.location.search;
        jinYueDate = decodeURIComponent(jinYueDate)
        jinYueDate = jinYueDate.slice(1);
        var date = new Date(jinYueDate).toISOString();
        // var date = new Date(jinYueDate);
        // date_value=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
        // date_value=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' ;
        //yyyy-MM-dd hh:mm:ss
        // var tripDates = date_value.toString();
        jinYueDate = date;
        jinYueDate = jinYueDate.slice(0,-1);
        jinYueDate = jinYueDate+'+0000'
        console.log(jinYueDate)
        // console.log(tripDates)
        // this.createDate = jinYueDate;
        this.tripDate = jinYueDate;
        // alert(jinYueDate);
        //测试所用
        // axios.post('http://192.168.1.183:8085/trip/add', {
        //     "title": "光武",
        //     "tripDate": "2018-08-20T06:17:45.000+0000",
        //     "startTime": "2018-08-15T06:17:45.000+0000",
        //     "endTime": "2018-08-18T06:17:45.000+0000",
        //     "oneCallTime": "2018-08-09T06:17:45.000+0000",
        //     "twoCallTime": "2018-08-09T06:17:45.000+0000",
        //     "content": "光武，光武",
        //     "tripUserid": '1110',
        //     "createDate": "2018-08-10T06:17:45.000+0000"
        //                    2018-08-26T16:00:00.000+0000
        // }).then(function (response) {
        // // 　　alert();
        //     console.log(response)
        // }).catch(function (error) {
        // 　　alert(error);
        // });
      }
    })
  </script>
</html>
